package com.ios.controller;

import com.ios.model.dto.SeatStatusDTO;
import com.ios.service.SeatStatusService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * 座位状态控制器
 */
@RestController
@RequestMapping("/seat/status")
public class SeatStatusController extends BaseController {

    @Autowired
    private SeatStatusService seatStatusService;

    /**
     * 获取座位状态
     * @param roomId 自习室ID
     * @param date 查询日期(yyyy-MM-dd格式)
     * @param timeSlot 时间段(1:上午,2:中午,3:晚上)
     * @return 座位状态列表
     */
    @GetMapping
    public AjaxResult getSeatStatus(
            @RequestParam Long roomId,
            @RequestParam String date,
            @RequestParam Integer timeSlot
    ) {
        try {
            Date queryDate = java.sql.Date.valueOf(date); // 转换日期格式
            List<SeatStatusDTO> seatStatusList = seatStatusService.getSeatStatus(roomId, queryDate, timeSlot);
            return success(seatStatusList);
        } catch (Exception e) {
            return error("查询座位状态失败: " + e.getMessage());
        }
    }
}